OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Jul 29, 2021 7:37 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 35 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Integrated debugger inside kernel
PostPosted: Wed Jun 23, 2021 6:26 am 
Offline
Member
Member
User avatar

Joined: Wed Feb 19, 2020 1:08 pm
Posts: 167
Location: Italy
I'm having some troubles making my os work on real hardware so to avoid recompiling every time I change something to test and burning to the physical disk I took some inspiration from bzt's minidbg and implemented something like that in my kernel. It works flawlessly on QEMU with named pipes but I can't make it work with a real computer. I have an rs232-USB cable which is plugged by the serial port in the computer with my os on, and the USB part is in my other pc. I tried with minicom but nothing happens and the port is "offline"; using cat on the port to read just sits there forever and echoing to the port does nothing. For some obscure reason once I achieved to issue a command to the debugger with echo but then nothing. What am I missing?

_________________
Greetings, Bonfra.


Top
 Profile  
 
 Post subject: Re: Integrated debugger inside kernel
PostPosted: Wed Jun 23, 2021 7:25 am 
Offline
Member
Member
User avatar

Joined: Mon Jan 15, 2018 2:27 pm
Posts: 184
The old trick to debug problems with RS-232 connection problems is to short RxD and TxD lines (pin 2 and 3 on standard connectors) together and see if it echoes sent characters back.


Top
 Profile  
 
 Post subject: Re: Integrated debugger inside kernel
PostPosted: Wed Jun 23, 2021 7:34 am 
Offline
Member
Member
User avatar

Joined: Wed Feb 19, 2020 1:08 pm
Posts: 167
Location: Italy
pvc wrote:
The old trick to debug problems with RS-232 connection problems is to short RxD and TxD lines (pin 2 and 3 on standard connectors) together and see if it echoes sent characters back.

Do I need to connect together those two pins on their own or does the cable need to be plugged to the other end? it's a bit trivial to shorten them while it's connected. I tried to connect just these two pins without plugging the cable and nothing is sent back, maybe I need to do something else with the other pins?

_________________
Greetings, Bonfra.


Top
 Profile  
 
 Post subject: Re: Integrated debugger inside kernel
PostPosted: Wed Jun 23, 2021 8:27 am 
Offline
Member
Member

Joined: Fri May 11, 2018 6:51 am
Posts: 201
Are you sure you’re accessing the real serial port on hardware? Keep in mind that legacy COM1 interface and similars on I/O port 0x3f8 etc. are not available on modern hardware, even if you have a built in serial controller. You’ll have to discover it on boot, and very likely use memory mapped IO.

_________________
Tilck, a Tiny Linux-Compatible Kernel: https://github.com/vvaltchev/tilck


Top
 Profile  
 
 Post subject: Re: Integrated debugger inside kernel
PostPosted: Wed Jun 23, 2021 10:33 am 
Offline
Member
Member
User avatar

Joined: Wed Feb 19, 2020 1:08 pm
Posts: 167
Location: Italy
vvaltchev wrote:
Are you sure you’re accessing the real serial port on hardware?

I'm connecting the cable to this port here:
Image
vvaltchev wrote:
Keep in mind that legacy COM1 interface and similars on I/O port 0x3f8 etc. are not available on modern hardware, even if you have a built in serial controller.

It's not really new; it's an optiplex 780 from 2010.
vvaltchev wrote:
You’ll have to discover it on boot, and very likely use memory mapped IO.

So I need to call some bios interrupt to get this information? which one?

_________________
Greetings, Bonfra.


Top
 Profile  
 
 Post subject: Re: Integrated debugger inside kernel
PostPosted: Wed Jun 23, 2021 11:23 am 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 754
Thats the same PC I use :) . It should have ISA serial ports in it. Only modern UEFI machines don't have thoose. Note that to find what port the serial port is at, you should check the BDA.


Top
 Profile  
 
 Post subject: Re: Integrated debugger inside kernel
PostPosted: Wed Jun 23, 2021 11:35 am 
Offline
Member
Member

Joined: Sun Jun 23, 2019 5:36 pm
Posts: 379
Location: North Dakota, United States
I'd love to integrate a kernel debugger into my kernel but BZT's debugger isn't portable to other languages. So I'm stuck there and have no idea how to actually "write" a debugger. :)
What's the process for discovering UARTs on modern machines? Would they just be PCI devices?
Sorry to go OT but if I could get something like this working it'd greatly speed up my dev process.


Top
 Profile  
 
 Post subject: Re: Integrated debugger inside kernel
PostPosted: Wed Jun 23, 2021 11:43 am 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 955
GDB has a standardized protocol (see the GDB documentation and our kernel implementation, it is not too complicated but a bit arcane). Since you're writing a kernel in Rust, you could make use of this crate (among others) which implements the GDB protocol (well, you still have to add your own hooks).

For discovering the UART: you can detect it via ACPI (that's the portable method), or hard code its PIO addresses (with a way for users to override these).

_________________
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].


Top
 Profile  
 
 Post subject: Re: Integrated debugger inside kernel
PostPosted: Wed Jun 23, 2021 12:17 pm 
Offline
Member
Member

Joined: Fri May 11, 2018 6:51 am
Posts: 201
Bonfra wrote:
vvaltchev wrote:
Are you sure you’re accessing the real serial port on hardware?

I'm connecting the cable to this port here:
I have no doubt you're connecting the cable in the right place. I was talking from the kernel point, if you're really accessing the controller that you're connecting. Legacy I/O ports like 0x3f8 might look like they're working, but in reality there's nothing on the HW side.

Bonfra wrote:
It's not really new; it's an optiplex 780 from 2010.
2010 means "super new". When it's about x86, with "modern" hardware kernel developers here usually mean anything after year 2000, that supports ACPI etc. In order use the 0x3f8 I/O port, you need a "legacy PC" machine, probably from mid '90s or older.

Bonfra wrote:
vvaltchev wrote:
You’ll have to discover it on boot, and very likely use memory mapped IO.

So I need to call some bios interrupt to get this information? which one?
As Korona said, you'd need to discover it via ACPI. It's a ton of work to get there. The quickest shortcut is to find UART's controller physical memory address using another operating system like Linux and (temporarily) hard-coding it in your project. I know it's far from great but.. "modern" hardware is complex to manage.

_________________
Tilck, a Tiny Linux-Compatible Kernel: https://github.com/vvaltchev/tilck


Top
 Profile  
 
 Post subject: Re: Integrated debugger inside kernel
PostPosted: Wed Jun 23, 2021 12:55 pm 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 955
@vvaltchev: Do you have physical hardware where 0x3F8 does not work? On the machines that I tested on (even newer ones), COM1 is still at that port (but COM 2, 3, 4 might not be at their legacy addresses - I have not checked that).

_________________
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].


Top
 Profile  
 
 Post subject: Re: Integrated debugger inside kernel
PostPosted: Wed Jun 23, 2021 2:02 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 19, 2020 1:08 pm
Posts: 167
Location: Italy
vvaltchev wrote:
As Korona said, you'd need to discover it via ACPI. It's a ton of work to get there. The quickest shortcut is to find UART's controller physical memory address using another operating system like Linux and (temporarily) hard-coding it in your project. I know it's far from great but.. "modern" hardware is complex to manage.

ACPI is a thing I didn't even consider since now, really hard in my opinion. Just to make it work I think I'm going to locate the address with Linux as you suggest. What is the command for doing this :) ?

_________________
Greetings, Bonfra.


Top
 Profile  
 
 Post subject: Re: Integrated debugger inside kernel
PostPosted: Wed Jun 23, 2021 2:10 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 3218
Open the BIOS setup and check the serial port configuration there. You might even be able to change which I/O port and IRQ it's assigned to.


Top
 Profile  
 
 Post subject: Re: Integrated debugger inside kernel
PostPosted: Wed Jun 23, 2021 2:23 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 19, 2020 1:08 pm
Posts: 167
Location: Italy
Octocontrabass wrote:
Open the BIOS setup and check the serial port configuration there. You might even be able to change which I/O port and IRQ it's assigned to.

This is the only thing about serial ports, it's already set on COM1 so this should be right.
Image

_________________
Greetings, Bonfra.


Top
 Profile  
 
 Post subject: Re: Integrated debugger inside kernel
PostPosted: Wed Jun 23, 2021 2:42 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 3218
Well, there you go. Your serial port is using I/O port 0x3F8 and (ISA) IRQ 4.

If the serial port doesn't echo back the data you send when you short pins 2 and 3 together (with nothing else connected), the UART isn't programmed correctly.


Top
 Profile  
 
 Post subject: Re: Integrated debugger inside kernel
PostPosted: Wed Jun 23, 2021 2:55 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 19, 2020 1:08 pm
Posts: 167
Location: Italy
I swear I didn't touch anything in the code but now from the other pc `echo "c" > /dev/ttyUSB0` to the serial cable now works and send the "c" command (in my case continue execution) so the os continues normally. But nothing is received. Like when the OS boots up it should print `integrated debugger initialized` and every command should send an acknowledge back. But nothing is cought by `cat < /dev/ttyUSB0`

_________________
Greetings, Bonfra.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 35 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group